package cn.hznc.controller.inventory;

import cn.hznc.aspect.BusinessType;
import cn.hznc.aspect.Log;
import cn.hznc.domain.request.inventory.*;
import cn.hznc.domain.request.toolpart.EditToolPartLengthAndRadiusReq;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.exception.ToolLifeCycleException;
import cn.hznc.controller.service.inventory.AssemblyToolInventoryService;
import cn.hznc.controller.service.inventory.InventoryLocationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @Author：Administrator
 * @Date：2023/4/9 21:22
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/assemblyInventory")
public class AssemblyToolInventoryController{

    @Autowired
    private AssemblyToolInventoryService assemBlyToolInventoryService;

    @Autowired
    private InventoryLocationService inventoryLocationService;

    /**
     * 条件查询总成刀具库位详情
     * @param locationToolDetailReq
     * @return
     */
    @RequestMapping(value = "/getLocationAssemblyToolDetail",method = RequestMethod.POST)
    public ResponseBody getLocationAssemblyToolDetail(@RequestBody LocationToolDetailReq locationToolDetailReq){
        try {
            return ResponseBody.success(assemBlyToolInventoryService.getLocationAssemblyToolDetail(locationToolDetailReq));
        } catch (ToolLifeCycleException e) {
            return ResponseBody.error(e.getCode(),e.getMsg());
        }
    }

    @RequestMapping(value = "/getAssemblyToolShelvesManageList",method = RequestMethod.POST)
    public ResponseBody getAssemblyToolShelvesManageList(@RequestBody ToolPartsManageReq toolPartsManageReq){
        return ResponseBody.success(assemBlyToolInventoryService.getAssemblyToolShelvesManageList(toolPartsManageReq));
    }

    @RequestMapping(value = "/getAssemblyToolManageList",method = RequestMethod.POST)
    public ResponseBody getAssemblyToolManageList(@RequestBody ToolPartsManageReq toolPartsManageReq){
        return ResponseBody.success(assemBlyToolInventoryService.getAssemblyToolManageList(toolPartsManageReq));
    }

    /**
     * 刀具总成库存详情
     * @param inventoryManageDetailReq
     * @return
     */
    @RequestMapping(value = "/getAssemblyToolDetail",method = RequestMethod.POST)
    public ResponseBody getAssemblyToolDetail(@RequestBody InventoryManageDetailReq inventoryManageDetailReq){
        return ResponseBody.success(assemBlyToolInventoryService.getAssemblyToolDetailList(inventoryManageDetailReq));
    }

    /**
     * 刀具零件库存详情
     * @param inventoryManageDetailReq
     * @return
     */
    @RequestMapping(value = "/getAssemblyToolLocationDetail",method = RequestMethod.POST)
    public ResponseBody getAssemblyToolLocationDetail(@RequestBody InventoryManageDetailReq inventoryManageDetailReq){
        return ResponseBody.success(assemBlyToolInventoryService.getAssemblyToolLocationDetail(inventoryManageDetailReq));
    }

    /**
     * 车间总成库位使用日志
     * @param locationAssemblyToolUsageReq
     * @return
     */
    @RequestMapping(value = "/getLocationAssemblyToolUsageLog" ,method = RequestMethod.POST)
    public ResponseBody getLocationAssemblyToolUsageLog(@RequestBody LocationAssemblyToolUsageReq locationAssemblyToolUsageReq){
        return ResponseBody.success(inventoryLocationService.getLocationAssemblyToolUsageLog(locationAssemblyToolUsageReq));
    }

    /**
     * 车间配刀状况
     * @param
     * @return
     */
    @RequestMapping(value = "/getToolAllocationStatus" ,method = RequestMethod.POST)
    public ResponseBody getToolAllocationStatus(@RequestBody ToolAllocationReq toolAllocationReq){
        return ResponseBody.success(inventoryLocationService.getToolAllocationStatus(toolAllocationReq));
    }

    @RequestMapping(value = "/queryNoManagementAssembleToolPart", method = RequestMethod.POST)
    public ResponseBody queryNoManagementAssembleToolPart(@RequestBody ToolPartsManageReq toolPartsManageReq){
        return ResponseBody.success(assemBlyToolInventoryService.queryNoManagementAssembleToolPart(toolPartsManageReq));
    }


    @RequestMapping(value = "/editToolPartLengthAndRadius", method = RequestMethod.POST)
    @Log(title = "修改零件长度半径" , businessType = BusinessType.UPDATE)
    public ResponseBody editToolPartLengthAndRadius(@RequestBody EditToolPartLengthAndRadiusReq editToolPartLengthAndRadiusReq){
        return ResponseBody.success(assemBlyToolInventoryService.editToolPartLengthAndRadius(editToolPartLengthAndRadiusReq));
    }

    @RequestMapping(value = "/qryAssemblyToolInfo", method = RequestMethod.GET)
    public ResponseBody qryAssemblyToolInfo(@RequestParam("rfid") String rfid){
        return ResponseBody.success(assemBlyToolInventoryService.qryAssemblyToolInfo(rfid));
    }

    @RequestMapping(value = "/queryAssemblyTool", method = RequestMethod.POST)
    public ResponseBody queryAssemblyTool(@RequestBody QueryAssemblyToolReq queryAssemblyToolReq){
        return ResponseBody.success(assemBlyToolInventoryService.queryAssemblyTool(queryAssemblyToolReq));
    }

    @RequestMapping(value = "/addOrEditAssemblyTool", method = RequestMethod.POST)
    @Log(title = "新增或修改库存总成类型" , businessType = BusinessType.OTHER)
    public ResponseBody addOrEditAssemblyTool(@RequestBody AddOrEditAssemblyToolReq addOrEditAssemblyToolReq){
        return ResponseBody.success(assemBlyToolInventoryService.addOrEditAssemblyTool(addOrEditAssemblyToolReq));
    }

    @RequestMapping(value = "/deleteAssemblyTool", method = RequestMethod.GET)
    @Log(title = "删除库存总成类型" , businessType = BusinessType.UPDATE)
    public ResponseBody deleteAssemblyTool(@RequestParam("id") Integer id){
        try {
            return ResponseBody.success(assemBlyToolInventoryService.deleteAssemblyTool(id));
        } catch (ToolLifeCycleException e) {
            return ResponseBody.error(e.getCode() , e.getMsg());
        }
    }

    @RequestMapping(value = "/countPhysicalInventory", method = RequestMethod.GET)
    public ResponseBody countPhysicalInventory(){
        return ResponseBody.success(assemBlyToolInventoryService.countPhysicalInventory());
    }

    @RequestMapping(value = "/toolReturnChart", method = RequestMethod.POST)
    public ResponseBody toolReturnChart(){
        return ResponseBody.success(assemBlyToolInventoryService.toolReturnChart());
    }

    @RequestMapping(value = "/checkToolNos", method = RequestMethod.GET)
    public ResponseBody checkToolNos(){
        return ResponseBody.success(assemBlyToolInventoryService.checkToolNos());
    }

    @RequestMapping(value = "/testSyncData", method = RequestMethod.GET)
    public ResponseBody testSyncData() throws ParseException {
        return ResponseBody.success(assemBlyToolInventoryService.testSyncData());
    }
}
